package com.febs.runner;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.stereotype.Component;

import java.net.InetAddress;

import lombok.extern.slf4j.Slf4j;

/**
 * @author zhongyj <1126834403@qq.com><br/>
 * @date 2020/1/21
 */
@Slf4j
@Component
public class StartedUpRunner implements ApplicationRunner {

    private ConfigurableApplicationContext context;

    @Autowired
    public StartedUpRunner(ConfigurableApplicationContext context) {
        this.context = context;
    }

    @Value("${server.port:8080}")
    private String port;
    @Value("${server.servlet.context-path:}")
    private String contextPath;


    @Override
    public void run(ApplicationArguments args) throws Exception {
        if (context.isActive()) {
            InetAddress address = InetAddress.getLocalHost();
            String url = String.format("http://%s:%s", address.getHostAddress(), port);
            if (StringUtils.isNotBlank(contextPath)) {
                url += contextPath;
            }

            log.info("|-------------------------------------------|");
            log.info("|    ______ ______ ____   _____             |");
            log.info("|   |  ____|  ____|  _ \\ / ____|           |");
            log.info("|   | |__  | |__  | |_) | (___              |");
            log.info("|   |  __| |  __| |  _ < \\___ \\           |");
            log.info("|   | |    | |____| |_) |____) |            |");
            log.info("|   |_|    |______|____/|_____/             |");
            log.info("|                                           |");
            log.info("|-------------------------------------------|");
            log.info("系统启动完毕，地址：{}", url);
            log.info("============= 启动成功 =============");
        }
    }
}

















